#ifndef __flist_H
#define __flist_H

#include "stdint.h"
#include "mytype.h"
#include "mem_buffer.h"

#ifdef __cplusplus
extern "C"
{
#endif

	typedef struct
	{
		const void** list;
		int len_now;
		int len_max;
		int (*comp)(const void* s1, const void* s2); 
		mem_fbuf_type* mem;				 
	} flist_obj_type;

	int flist_init(flist_obj_type* list, const void** listobj, int len_max, int (*comp)(const void* s1, const void* s2), mem_fbuf_type* mem);

	int flist_search(flist_obj_type* list, const void* obj);

	int flist_add(flist_obj_type* list, const void* obj, int obj_size, char unique);

	int flist_insert(flist_obj_type* list, int site, const void* obj, int obj_size);

	int flist_del_at(flist_obj_type* list, int site);

	int flist_del(flist_obj_type* list, const void* obj);

	int flist_order_search(flist_obj_type* list, const void* obj, bisect_mode_type mode);

	int flist_order_add(flist_obj_type* flist, const void* obj, int obj_size, char unique);

	int flist_order_insert(flist_obj_type* flist, int site, const void* obj, int obj_size);

	int flist_order_del(flist_obj_type* flist, const void* obj);

	typedef struct
	{
		flist_obj_type flist;
		int mem_len_limit; 
	} mlist_obj_type;

	int mlist_init(mlist_obj_type* mlist, int mem_len_limit, int len_init, int (*comp)(const void* s1, const void* s2), mem_fbuf_type* mem);
	int mlist_search(mlist_obj_type* mlist, const void* obj);
	int mlist_add(mlist_obj_type* mlist, const void* obj, int obj_size, char unique);
	int mlist_insert(mlist_obj_type* mlist, int site, const void* obj, int obj_size);
	int mlist_del_at(mlist_obj_type* mlist, int site);
	int mlist_del(mlist_obj_type* mlist, const void* obj);
	int mlist_order_search(mlist_obj_type* mlist, const void* obj, bisect_mode_type mode);
	int mlist_order_add(mlist_obj_type* mlist, const void* obj, int obj_size, char unique);
	int mlist_order_insert(mlist_obj_type* mlist, int site, const void* obj, int obj_size);
	int mlist_order_del(mlist_obj_type* mlist, const void* obj);
	int mlist_free(mlist_obj_type* mlist);

	typedef struct
	{
		size_t* list;
		int len_now;
		int len_max;
		int (*comp)(const void* s1, const void* s2); 
		mem_mbuf_type* mem;
	} flist_mbase_obj_type;

	typedef struct
	{
		flist_mbase_obj_type flist;
		int mem_len_limit; 
	} mlist_mbase_obj_type;

	int flist_mbase_init(flist_mbase_obj_type* list, size_t* listobj, int len_max, int (*comp)(const void* s1, const void* s2), mem_mbuf_type* mem);
	int flist_mbase_search(flist_mbase_obj_type* list, const void* obj);
	int flist_mbase_add(flist_mbase_obj_type* list, const void* obj, int obj_size, char unique);
	int flist_mbase_insert(flist_mbase_obj_type* list, int site, const void* obj, int obj_size);
	int flist_mbase_del_at(flist_mbase_obj_type* list, int site);
	int flist_mbase_del(flist_mbase_obj_type* list, const void* obj);
	int flist_mbase_order_search(flist_mbase_obj_type* list, const void* obj, bisect_mode_type mode);
	int flist_mbase_order_add(flist_mbase_obj_type* flist, const void* obj, int obj_size, char unique);
	int flist_mbase_order_insert(flist_mbase_obj_type* flist, int site, const void* obj, int obj_size);
	int flist_mbase_order_del(flist_mbase_obj_type* flist, const void* obj);

	int mlist_mbase_init(mlist_mbase_obj_type* mlist, int mem_len_limit, int len_init, int (*comp)(const void* s1, const void* s2), mem_mbuf_type* mem);
	int mlist_mbase_search(mlist_mbase_obj_type* mlist, const void* obj);
	int mlist_mbase_add(mlist_mbase_obj_type* mlist, const void* obj, int obj_size, char unique);
	int mlist_mbase_insert(mlist_mbase_obj_type* mlist, int site, const void* obj, int obj_size);
	int mlist_mbase_del_at(mlist_mbase_obj_type* mlist, int site);
	int mlist_mbase_del(mlist_mbase_obj_type* mlist, const void* obj);
	int mlist_mbase_order_search(mlist_mbase_obj_type* mlist, const void* obj, bisect_mode_type mode);
	int mlist_mbase_order_add(mlist_mbase_obj_type* mlist, const void* obj, int obj_size, char unique);
	int mlist_mbase_order_insert(mlist_mbase_obj_type* mlist, int site, const void* obj, int obj_size);
	int mlist_mbase_order_del(mlist_mbase_obj_type* mlist, const void* obj);
	int mlist_mbase_free(mlist_mbase_obj_type* mlist);

#define flist_mbase_obj(flist, site) ((void*)(flist.mem->mem + flist.list[site]))
#define mlist_mbase_obj(mlist, site) ((void*)(mlist.flist.mem->mem + mlist.flist.list[site]))

	typedef struct
	{
		const void* list;
		int len_now;
		int len_max;
		int obj_size;
		int (*comp)(const void* s1, const void* s2); 
	} vflist_obj_type;

	int vflist_init(vflist_obj_type* list, const void* obj_list, int len_max, int obj_size);

	int vflist_search(vflist_obj_type* list, const void* obj);

	int vflist_add(vflist_obj_type* list, const void* obj, char unique);

	int vflist_insert(vflist_obj_type* list, int site, const void* obj);

	int vflist_del_at(vflist_obj_type* list, int site);

	int vflist_del(vflist_obj_type* list, const void* obj);

	int vflist_order_search(vflist_obj_type* list, const void* obj, bisect_mode_type mode);

	int vflist_order_add(vflist_obj_type* flist, const void* obj, char unique);

	int vflist_order_insert(vflist_obj_type* flist, int site, const void* obj);

	int vflist_order_del(vflist_obj_type* flist, const void* obj);

	typedef struct
	{
		vflist_obj_type flist;
		int mem_len_limit; 
	} vmlist_obj_type;

	int vmlist_init(vmlist_obj_type* mlist, int mem_len_limit, int len_init, int obj_size, int (*comp)(const void* s1, const void* s2));
	int vmlist_search(vmlist_obj_type* mlist, const void* obj);
	int vmlist_add(vmlist_obj_type* mlist, const void* obj, char unique);
	int vmlist_insert(vmlist_obj_type* mlist, int site, const void* obj);
	int vmlist_del_at(vmlist_obj_type* mlist, int site);
	int vmlist_del(vmlist_obj_type* mlist, const void* obj);
	int vmlist_order_search(vmlist_obj_type* mlist, const void* obj, bisect_mode_type mode);
	int vmlist_order_add(vmlist_obj_type* mlist, const void* obj, char unique);
	int vmlist_order_insert(vmlist_obj_type* mlist, int site, const void* obj);
	int vmlist_order_del(vmlist_obj_type* mlist, const void* obj);
	int vmlist_free(vmlist_obj_type* mlist);

	typedef struct
	{
		const char** list;
		int len_now;
		int len_max;
		mem_fbuf_type* mem; 
	} fslist_obj_type;

	int fslist_init(fslist_obj_type* list, const char** listobj, int len_max, mem_fbuf_type* mem);
	int fslist_search(fslist_obj_type* list, const char* str);
	int fslist_add(fslist_obj_type* list, const char* str, char unique);
	int fslist_insert(fslist_obj_type* list, int site, const char* str);
	int fslist_del_at(fslist_obj_type* list, int site);
	int fslist_del(fslist_obj_type* list, const char* str);
	int fslist_order_search(fslist_obj_type* list, const char* str, bisect_mode_type mode);
	int fslist_order_add(fslist_obj_type* flist, const char* str, char unique);
	int fslist_order_insert(fslist_obj_type* flist, int site, const char* str);
	int fslist_order_del(fslist_obj_type* flist, const char* str);

	typedef struct
	{
		fslist_obj_type flist;
		int mem_len_limit; 
	} mslist_obj_type;

	int mslist_init(mslist_obj_type* mlist, int mem_len_limit, int len_init, mem_fbuf_type* mem);
	int mslist_search(mslist_obj_type* mlist, const char* str);
	int mslist_add(mslist_obj_type* mlist, const char* str, char unique);
	int mslist_insert(mslist_obj_type* mlist, int site, const char* str);
	int mslist_del_at(mslist_obj_type* mlist, int site);
	int mslist_del(mslist_obj_type* mlist, const char* str);
	int mslist_order_search(mslist_obj_type* mlist, const char* str, bisect_mode_type mode);
	int mslist_order_add(mslist_obj_type* mlist, const char* str, char unique);
	int mslist_order_insert(mslist_obj_type* mlist, int site, const char* str);
	int mslist_order_del(mslist_obj_type* mlist, const char* str);
	int mslist_free(mslist_obj_type* mlist);

	typedef struct
	{
		size_t* list;
		int len_now;
		int len_max;
		mem_mbuf_type* mem;
	} fslist_mbase_obj_type;

	typedef struct
	{
		fslist_mbase_obj_type flist;
		int mem_len_limit; 
	} mslist_mbase_obj_type;

	int fslist_mbase_init(fslist_mbase_obj_type* list, size_t* listobj, int len_max, mem_mbuf_type* mem);
	int fslist_mbase_search(fslist_mbase_obj_type* list, const char* str);
	int fslist_mbase_add(fslist_mbase_obj_type* list, const char* str, char unique);
	int fslist_mbase_insert(fslist_mbase_obj_type* list, int site, const char* str);
	int fslist_mbase_del_at(fslist_mbase_obj_type* list, int site);
	int fslist_mbase_del(fslist_mbase_obj_type* list, const char* str);
	int fslist_mbase_order_search(fslist_mbase_obj_type* list, const char* str, bisect_mode_type mode);
	int fslist_mbase_order_add(fslist_mbase_obj_type* flist, const char* str, char unique);
	int fslist_mbase_order_insert(fslist_mbase_obj_type* flist, int site, const char* str);
	int fslist_mbase_order_del(fslist_mbase_obj_type* flist, const char* str);

	int mslist_mbase_init(mslist_mbase_obj_type* mlist, int mem_len_limit, int len_init, mem_mbuf_type* mem);
	int mslist_mbase_search(mslist_mbase_obj_type* mlist, const char* str);
	int mslist_mbase_add(mslist_mbase_obj_type* mlist, const char* str, char unique);
	int mslist_mbase_insert(mslist_mbase_obj_type* mlist, int site, const char* str);
	int mslist_mbase_del_at(mslist_mbase_obj_type* mlist, int site);
	int mslist_mbase_del(mslist_mbase_obj_type* mlist, const char* str);
	int mslist_mbase_order_search(mslist_mbase_obj_type* mlist, const char* str, bisect_mode_type mode);
	int mslist_mbase_order_add(mslist_mbase_obj_type* mlist, const char* str, char unique);
	int mslist_mbase_order_insert(mslist_mbase_obj_type* mlist, int site, const char* str);
	int mslist_mbase_order_del(mslist_mbase_obj_type* mlist, const char* str);
	int mslist_mbase_free(mslist_mbase_obj_type* mlist);

#define fslist_mbase_str(flist, site) ((char*)flist.mem->mem + flist.list[site])
#define mslist_mbase_str(mlist, site) ((char*)mlist.flist.mem->mem + mlist.flist.list[site])

#ifdef __cplusplus
}
#endif

#endif 
